package com.example.carrierapp.viewmodel.viewmodel

import android.databinding.BaseObservable
import android.databinding.Bindable
import android.graphics.Color
import android.text.SpannableString
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import com.example.carrierapp.util.DateUtils
import com.example.carrierapp.viewmodel.itemmodel.ItemGoodsSourceModel
import com.example.lb.fingerdemo.BR
import com.example.lb.fingerdemo.R
import com.google.gson.annotations.SerializedName

class GoodsSourceDetailsModel : BaseObservable() {

    @Bindable
    var details = false
        set(value) {
            field = value
            notifyPropertyChanged(BR.canInput)
            notifyPropertyChanged(BR.details)
        }

    @Bindable
    var onDeal = false
        set(value) {
            field = value
            notifyPropertyChanged(BR.onDeal)
        }

    var biddingId = 0 //招标id

    var totalCount = 0 //总条数

    @Bindable
    var bidCode = "" //招标编码

    var bidMark = 0 //中标标识 -1未中标 0默认 1主 2一分 3二分 4三分 5四分
        set(value) {
            field = value
            notifyPropertyChanged(BR.bidIcon)
        }

    @Bindable
    var bidIcon = -1
        get() =
            when (bidMark) {
                1 -> R.mipmap.icon_master_the_winning
                2 -> R.mipmap.icon_one
                3 -> R.mipmap.icon_two
                4 -> R.mipmap.icon_three
                5 -> R.mipmap.icon_four
                else -> R.mipmap.icon_not_the_winning
            }

    @SerializedName("biddingLineList", alternate = ["robbingDetailList"])
    var biddingLineList: MutableList<ItemGoodsSourceModel>? = null

    var countDownSeconds = 0L // 倒计时秒数

    @Bindable
    var time = ""

    var adminName = "" //业务人员名称

    var adminPhone = "" //业务人员电话

    var isPriced = false //是否已报过价 用于判断重新报价

    var isCombination = false //是否组合竞标

    var robbingPattern = 1 //竟抢模式 1=竞价 2=考评分竞价 3=抢单

    var payText = ""
        get() = if (robbingPattern == 3) "抢单" else "提交报价"

    var roles = ""
        get() = when (robbingPattern) {
            3 -> "先抢先得"
            else -> if (isCombination) "所有线路运费最低者中标" else "报价最低者中标"
        }

    fun notifyTime() {
        time = DateUtils.secondsToString(countDownSeconds)
        notifyPropertyChanged(BR.time)
    }
}